package com.ly.web.controller.erp;

import java.util.List;

import com.ly.heart.domain.dto.KingApplyAllocateDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.KingApplyAllocateEntity;
import com.ly.heart.service.IKingApplyAllocateService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

/**
 * 调拨申请单Controller
 * 
 * @author wutao
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/heart/applyAllocate")
public class KingApplyAllocateController extends BaseController
{
    @Autowired
    private IKingApplyAllocateService kingApplyAllocateService;

    /**
     * 查询调拨申请单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:list')")
    @GetMapping("/list")
    public AjaxResult list(KingApplyAllocateDto kingApplyAllocateDto)
    {
        return AjaxResult.success(kingApplyAllocateService.selectKingApplyAllocateListPage(kingApplyAllocateDto));
    }

    /**
     * 导出调拨申请单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:export')")
    @Log(title = "调拨申请单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KingApplyAllocateEntity kingApplyAllocate)
    {
        List<KingApplyAllocateEntity> list = kingApplyAllocateService.selectKingApplyAllocateList(kingApplyAllocate);
        ExcelUtil<KingApplyAllocateEntity> util = new ExcelUtil<KingApplyAllocateEntity>(KingApplyAllocateEntity.class);
        return util.exportExcel(list, "applyAllocate");
    }

    /**
     * 获取调拨申请单详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(kingApplyAllocateService.selectKingApplyAllocateById(id));
    }


    /**
     * 暂存金蝶-调拨申请单
     * @param kingApplyAllocate
     * @return
     */
    @ApiOperation("暂存金蝶-调拨申请单")
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:draft')")
    @Log(title = "暂存金蝶-调拨申请单", businessType = BusinessType.INSERT)
    @PostMapping("/draft")
    public AjaxResult draft(@RequestBody KingApplyAllocateEntity kingApplyAllocate)
    {
        return kingApplyAllocateService.draft(kingApplyAllocate);
    }

    /**
     * 保存金蝶-调拨申请单
     * @param kingApplyAllocate
     * @return
     */

    @ApiOperation("保存金蝶-调拨申请单")
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:submit')")
    @Log(title = "保存金蝶-调拨申请单", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody KingApplyAllocateEntity kingApplyAllocate)
    {
        return kingApplyAllocateService.submit(kingApplyAllocate);
    }

//    /**
//     * 修改调拨申请单
//     */
//    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:edit')")
//    @Log(title = "调拨申请单", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody KingApplyAllocateEntity kingApplyAllocate)
//    {
//        return toAjax(kingApplyAllocateService.updateKingApplyAllocate(kingApplyAllocate));
//    }

    /**
     * 删除调拨申请单
     */
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:remove')")
    @Log(title = "调拨申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return kingApplyAllocateService.deleteKingApplyAllocateByIds(ids);
    }
}
